package lsf.itcast.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lsf.itcast.domain.Orders;
import lsf.itcast.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
   private OrdersService ordersService;

    //查询所有订单------同时设置分页查询(利用分页插件)，必须接受前台参数，同时跳转页面
    @RequestMapping("/findAll.do")
    public ModelAndView findAll(/*分页后*/@RequestParam(name ="page",required =true,defaultValue ="1")int page,
                         @RequestParam(name ="size",defaultValue ="4")int pageSize  ){
        ModelAndView mv = new ModelAndView();
        List<Orders> orders = ordersService.findAllOrder(page,pageSize);
       // mv.addObject("ordersList",orders);
        //mv.setViewName("orders-list");// 分页前

        //分页查询之后;pageInfo是一个分页查询的bean类
        PageInfo pageInfo = new PageInfo(orders);
       mv.addObject("pageInfo",pageInfo);
       mv.setViewName("orders-page-list");
        return mv;
    }

    //查询订单详情，包含产品信息，旅客信息
    @RequestMapping("/findById.do")
    public ModelAndView findById(@RequestParam(name = "id",required = true) String id){
        ModelAndView mv = new ModelAndView();
        Orders order = ordersService.findById(id);
        mv.addObject("orders",order);
        mv.setViewName("orders-show");
        return mv;
    }
}
